package com.share.device.controller;

import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.core.web.page.TableDataInfo;
import com.share.device.domain.Cabinet;
import com.share.device.service.ICabinetService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@Tag(name = "充电宝柜机接口管理")
@RestController
@RequestMapping("/cabinet")
public class CabinetController extends BaseController {
    @Autowired
    private ICabinetService cabinetService;

    @Operation(summary = "分页获取充电宝柜机列表")
    @GetMapping("/list")
    public TableDataInfo cabinetlist(Cabinet cabinet) {
        startPage();
        return getDataTable(cabinetService.selectCabinetlist(cabinet));
    }

    @Operation(summary = "获取全部充电宝柜机列表")
    @GetMapping("/all")
    public AjaxResult cabinetAll() {
        return success(cabinetService.list());
    }

    @Operation(summary = "添加")
    @PostMapping
    public AjaxResult add(@RequestBody Cabinet cabinet) {
        return success(cabinetService.save(cabinet));
    }

    @Operation(summary = "修改")
    @PutMapping
    public AjaxResult update(@RequestBody Cabinet cabinet) {
        return success(cabinetService.updateById(cabinet));
    }

    @Operation(summary = "删除")
    @DeleteMapping("/{ids}")
    public AjaxResult delete(@PathVariable Long[] ids) {
        return success(cabinetService.removeByIds(Arrays.asList(ids)));
    }

    @Operation(summary = "根据id查询详情")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(cabinetService.getById(id));
    }

    @Operation(summary = "搜索未使用柜机")
    @GetMapping(value = "/searchNoUseList/{keyword}")
    public AjaxResult searchNoUseList(@PathVariable String keyword) {
        return success(cabinetService.lambdaQuery().eq(Cabinet::getStatus, "0").like(Cabinet::getCabinetNo, keyword).list());
    }
}
